package com.weishi.common.utils.timing;

import org.springframework.stereotype.Component;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import java.util.Timer;
import java.util.TimerTask;

/**
 * 定时任务( 新增心率相关 )
 */
@Component
public class DataMoveTask implements ServletContextListener {

    private Timer timer = null;

    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {
        timer = new Timer(true);
        servletContextEvent.getServletContext().log("定时器已启动");
        timer.schedule(new OneTask(),60000,5000);//延迟60秒，定时5秒
    }

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {
        if (timer != null) {
            timer.cancel();
            servletContextEvent.getServletContext().log("定时器销毁");
        }
    }

    class OneTask extends TimerTask {//继承TimerTask类

        @Override
        public void run() {

            /**
             * 业务逻辑代码编写处
             */
            //System.out.println("执行业务逻辑代码！");








        }
    }





}
